package com.distribute.framework.model;

import com.distribute.framework.core.web.helper.Utils;
import java.lang.reflect.Field;
import java.util.Date; 
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;

import javax.annotation.Resource;

import com.distribute.framework.core.web.util.Page;
import com.distribute.framework.core.lang.*; 
import com.distribute.framework.core.web.helper.WebHelper.LzMap;
import com.distribute.framework.core.util.Function;
import com.distribute.framework.core.util.IbatisMap;
import com.distribute.framework.config.*;
import com.distribute.framework.plugin.*;

@namespace("delivery/replenishment")
public @caption("补货明细") @database(DatabaseNames.distribute_sys) @source("distribute_sys") @table("replenishment") class Replenishment implements java.io.Serializable
{
	private static final long serialVersionUID = 1l;
	private @caption("编号") @column("id")    @primary  @notnull  @note("  ") Long id;// 主键 非空     
	private @caption("补货信息") @column("replenish")     @notnull  @relate("$replenish") @RelateClass(Replenish.class)  @note("  ") Long replenish;// 非空     
 	private transient Replenish $replenish;//关联对象[配送商补货]
	private @caption("备注") @column("remarks") @like    @notnull  @note("  ") String remarks;// 非空     
	private @caption("规格属性") @column("attribute")      @note("  ") String attribute;//     
	private @caption("单位") @column("company")      @note("  商品单位") String company;//  商品单位   
	private @caption("已补货") @column("count")      @note("  ") Integer count;//     
	private @caption("已配出") @column("match_out")      @note("  ") Integer matchOut;//     
	private @caption("还欠") @column("owe")      @note("  ") Integer owe;//     
	private @caption("补货商品") @column("commodity")     @notnull  @relate("$commodity") @RelateClass(Commodity.class)  @note("  ") Long commodity;// 非空     
 	private transient Commodity $commodity;//关联对象[商品信息]
	private @caption("修改时间") @column("update_time")     @notnull  @note("  ") Date updateTime;// 非空     
	private @caption("添加时间") @column("add_time")     @notnull  @note("  ") Date addTime;// 非空     
	private @caption("状态") @column("status")     @notnull  @note(" 1:正常 0:无效  ") Short status;// 非空 1:正常 0:无效     
	 
	//默认构造函数
	public Replenishment(){ 
	
	}
	
	//主键构造函数
	public Replenishment(Long id){
		this.id = id;
	}
	
	/**所有字段构造函数 
	 Replenishment(
	 	Utils.getLong("replenish")//补货信息 [非空]
	 	,Utils.getString("remarks")//备注 [非空]
	 	,Utils.getString("attribute")//规格属性
	 	,Utils.getString("company")//单位
	 	,Utils.getInteger("count")//已补货
	 	,Utils.getInteger("matchOut")//已配出
	 	,Utils.getInteger("owe")//还欠
	 	,Utils.getLong("commodity")//补货商品 [非空]
	 	,Utils.getDate("updateTime")//修改时间 [非空]
	 	,Utils.getDate("addTime")//添加时间 [非空]
	 	,Utils.getShort("status")//状态 [非空]
	 )
	**/
	public Replenishment(Long replenish,String remarks,String attribute,String company,Integer count,Integer matchOut,Integer owe,Long commodity,Date updateTime,Date addTime,Short status){
		this.replenish=replenish;
		this.remarks=remarks;
		this.attribute=attribute;
		this.company=company;
		this.count=count;
		this.matchOut=matchOut;
		this.owe=owe;
		this.commodity=commodity;
		this.updateTime=updateTime;
		this.addTime=addTime;
		this.status=status;
	}
	
	//设置非空字段
	public Replenishment setNotNull(Long replenish,String remarks,Long commodity,Date updateTime,Date addTime,Short status){
		this.replenish=replenish;
		this.remarks=remarks;
		this.commodity=commodity;
		this.updateTime=updateTime;
		this.addTime=addTime;
		this.status=status;
		return this;
	}
	/** 编号 [非空]       **/
	public Replenishment id(Long id){
		this.id = id;
		this.setSeted(F.id);
		return this;
	}
	/** 补货信息 [非空] [Replenish]      **/
	public Replenishment replenish(Long replenish){
		this.replenish = replenish;
		this.setSeted(F.replenish);
		return this;
	}
	/** 备注 [非空]       **/
	public Replenishment remarks(String remarks){
		this.remarks = remarks;
		this.setSeted(F.remarks);
		return this;
	}
	/** 规格属性        **/
	public Replenishment attribute(String attribute){
		this.attribute = attribute;
		this.setSeted(F.attribute);
		return this;
	}
	/** 单位     商品单位   **/
	public Replenishment company(String company){
		this.company = company;
		this.setSeted(F.company);
		return this;
	}
	/** 已补货        **/
	public Replenishment count(Integer count){
		this.count = count;
		this.setSeted(F.count);
		return this;
	}
	/** 已配出        **/
	public Replenishment matchOut(Integer matchOut){
		this.matchOut = matchOut;
		this.setSeted(F.matchOut);
		return this;
	}
	/** 还欠        **/
	public Replenishment owe(Integer owe){
		this.owe = owe;
		this.setSeted(F.owe);
		return this;
	}
	/** 补货商品 [非空] [Commodity]      **/
	public Replenishment commodity(Long commodity){
		this.commodity = commodity;
		this.setSeted(F.commodity);
		return this;
	}
	/** 修改时间 [非空]       **/
	public Replenishment updateTime(Date updateTime){
		this.updateTime = updateTime;
		this.setSeted(F.updateTime);
		return this;
	}
	/** 添加时间 [非空]       **/
	public Replenishment addTime(Date addTime){
		this.addTime = addTime;
		this.setSeted(F.addTime);
		return this;
	}
	/** 状态 [非空]   1:正常 0:无效     **/
	public Replenishment status(Short status){
		this.status = status;
		this.setSeted(F.status);
		return this;
	}
	
	
	/**
	* 克隆对象
	**/
	public Replenishment clone(){
		Replenishment clone = new Replenishment();
		clone.replenish=this.replenish;
		clone.remarks=this.remarks;
		clone.attribute=this.attribute;
		clone.company=this.company;
		clone.count=this.count;
		clone.matchOut=this.matchOut;
		clone.owe=this.owe;
		clone.commodity=this.commodity;
		clone.updateTime=this.updateTime;
		clone.addTime=this.addTime;
		clone.status=this.status;
		return clone;
	}
	
	
	/**
	 * 根据ID取补货明细
	 * @param id
	 * @return
	 */
	public static @api Replenishment get(Long id){		
		return getReplenishmentById(id);
	}
	
	/**
	 * 获取所有补货明细
	 * @return
	 */
	public static @api List<Replenishment> list(Map params,Integer size){
		return getReplenishmentList(params,size);
	}
	/**
	 * 获取补货明细分页
	 * @return
	 */
	public static @api Page<Replenishment> page(Integer page,Integer size,Map params){
		return getReplenishmentPage(page, size , params);
	}
	
	
	/**
	 * 根据查询条件取补货明细
	 * @param params
	 * @return
	 */
	public static @api Replenishment Get(Map params){
		return getReplenishment(params);
	}
	/**
	 * 获取补货明细数
	 * @return
	 */
	public static @api Long count(Map params){
		return getReplenishmentCount(params);
	}
	/**
	 * 获取补货明细数
	 * @return
	 */
	public static @api <T> T eval(String eval,Map params){
		return getReplenishmentEval(eval,params);
	}
	/**
	 * 获取补货明细图表统计数据
	 * @param params 查询条件
	 * @param sumKey 统计的字段
	 * @param groupKey 1:按年， 2：按月， 3：按周， 4：按日， 5：按小时， 6：月分， 7：日分， 8：点分
	 * @return
	 */
	public static @api List<Map> stats(Map params,C sumKey,C groupKey){
		return getReplenishmentStats(params,sumKey,groupKey,-1);
	}
	/**
	 * 获取补货明细图表统计数据
	 * @param params 查询条件
	 * @param sumKey 统计的字段
	 * @param groupKey 分组的字段
	 * @param dateType 1:按年， 2：按月， 3：按周， 4：按日， 5：按小时， 6：月分， 7：日分， 8：点分
	 * @return
	 */
	public static @api List<Map> stats(Map params,C sumKey,C groupKey,int dateType){
		return getReplenishmentStats(params,sumKey,groupKey,dateType);
	}
	
	/**
	 * 根据ID取补货明细
	 * @param id
	 * @return
	 */
	public static @api Replenishment getReplenishmentById(Long id){		
		return getReplenishmentDao().getReplenishmentById(id);
	}
	
	
	/**
	 * 根据ID取补货明细的标识键值
	 * @param id
	 * @return
	 */
	public static @api String getKeyValue(Object key){
		Long id = Utils.parseLong(key);	
		if(id==null || id.longValue()==0 ){
			return null;
		}
		String value = null;
		if(value==null){
			Replenishment replenishment = get(id);
			if(replenishment!=null){
				String strValue = replenishment.getId$();
				value = strValue;
			}else{
				value = "{"+id+"}";
			}
		}
		/************LAZY3Q_ID_KEYVALUE************/
		/************LAZY3Q_ID_KEYVALUE************/
		return value;
	}	
	
	
	/**
	 * 获取当前对象的键值
	 * @return
	 */
	public String getKeyValue(){
		/************LAZY3Q_CODE_KEYVALUE************/
		/************LAZY3Q_CODE_KEYVALUE************/
		String keyValue = this.getId$();
		return keyValue;
	}
	
	
	/**
	 * 根据关键字精确查询补货明细对象
	 * @return
	 */
	public static @api Replenishment find(String key){
		if(Utils.empty(key))return null;
		Map params = new HashMap();
		if(key.toLowerCase().startsWith("id:"))//如果查询条件以id:开头，则按ID查询
			params.put("id", key.toLowerCase().replaceFirst("id:", ""));					
		else{//按标识查询，精确查询
			String strDefinex = "";
			strDefinex="(2=1 "+strDefinex+")";
			params.put("definex",strDefinex);
		}
		/************LAZY3Q_CODE_FIND************/
		/************LAZY3Q_CODE_FIND************/
		return Replenishment.getReplenishment(params);
	}
	
	
	/**
	 * 根据关键字查询补货明细
	 * @return
	 */
	public static @api List<Map> query(String key,int size,Map params,Boolean bObject){
		if(Utils.empty((String)params.get("asc")) && Utils.empty((String)params.get("desc")))//如果未传入排序字段
			params.put("desc","id");//那么，默认以主键降序，传给Dao层
		String strTerm=key;		
		if(!Utils.empty(strTerm)){
			if(strTerm.toLowerCase().startsWith("id:"))//如果查询条件以id:开头，则按ID查询
				params.put("id", strTerm.toLowerCase().replaceFirst("id:", ""));					
			else//按标识查询，模糊查询请带%
			{
				String strDefinex = "";
				strDefinex="(2=1 "+strDefinex+")";
				params.put("definex",strDefinex);
			}
		}
		/************LAZY3Q_CODE_QUERY************/
		/************LAZY3Q_CODE_QUERY************/
			
		List<Replenishment> list = page(0,size,params).getResult();
		
		/**
		* OK!取到数据拼成放入Map中，[{value,text,object:{...}},...]
		* value:数据ID，text:数据标识,object,整个对象
		**/
		List<Map> result = new java.util.ArrayList();
		for(Replenishment replenishment:list){
			Map map = new HashMap();
			map.put("key",replenishment.getId().toString());
			map.put("value", Utils.js(replenishment.getKeyValue()));
			if(bObject==true)
				map.put("object",replenishment);
			result.add(map);
		}
		/************LAZY3Q_AFTER_QUERY************/
		/************LAZY3Q_AFTER_QUERY************/
		
		return result;
	}
	
	
	
	/**
	 * 获取所有补货明细
	 * @return
	 */
	public static @api List<Replenishment> getReplenishmentList(Map params,Integer size){
		return getReplenishmentDao().getReplenishmentList(params,0,size);
	}
	
	/**
	 * 获取补货明细分页
	 * @return
	 */
	public static @api Page<Replenishment> getReplenishmentPage(Integer page,Integer size,Map params){
		if(page==null)page=0;
		if(size==null)size=20;
		return getReplenishmentDao().getReplenishmentPage(page, size , params);
	}
	
	/**
	 * 根据查询条件取补货明细
	 * @param params
	 * @return
	 */
	public static @api Replenishment getReplenishment(Map params){
		return getReplenishmentDao().getReplenishment(params);
	}
	
	/**
	 * 保存一个补货明细
	 * @param replenishment
	 * @return
	 */
	public static @api Replenishment saveReplenishment(Replenishment replenishment){
		return getReplenishmentDao().saveReplenishment(replenishment);
	}
	
	/**
	 * 根据条件更新补货明细
	 * @param values
	 * @param params
	 */
	public static @api int updateReplenishmentByConfirm(Map values, Map params){
		return getReplenishmentDao().updateReplenishmentByConfirm(values,params);
	}
	
	/**
	 * 修改一个补货明细
	 * @param replenishment
	 * @return
	 */
	public static @api int updateReplenishment(Replenishment replenishment){
		return getReplenishmentDao().updateReplenishment(replenishment);
	}
	
	/**
	 * 更新补货明细非空字段
	 * @param replenishment
	 */
	public static @api int updateReplenishment$NotNull(Replenishment replenishment){
		return getReplenishmentDao().updateReplenishment$NotNull(replenishment);
	}
	
	/**
	 * 获取补货明细数
	 * @return
	 */
	public static @api Long getReplenishmentCount(Map params){
		return getReplenishmentDao().getReplenishmentCount(params);
	}
		
		
	/**
	 * 获取补货明细自定义求和表达式,比如求和:eval="sum(id)"
	 * @return
	 */	
	public static @api <T> T getReplenishmentEval(String eval,Map params){
		return getReplenishmentDao().getReplenishmentEval(eval,params);
	}
	/**
	 * 获取补货明细图表统计数据
	 * @param params 查询条件
	 * @param sumKey 统计的字段
	 * @param groupKey 分组的字段
	 * @param dateType 1:按年， 2：按月， 3：按周， 4：按日， 5：按小时， 6：月分， 7：日分， 8：点分
	 * @return
	 */
	public static @api List<Map> getReplenishmentStats(Map params,C sumKey,C groupKey,int dateType){
		//TODO:图表统计功能未实现
		
		Map<String,Object> groups=new HashMap();//要分组的字段
		Map<String,Object> sums=new HashMap();//要统计的字段
		
		String[][] dateFormats=new String[][]{
				null,
				new String[]{"%Y","yyyy年","Y"},
				new String[]{"%Y-%m","yyyy年MM月","M"},
				new String[]{"%Y%U","yyyy年第ww周","W"},
				new String[]{"%Y-%m-%d","yyyy年MM月dd日","D"},
				new String[]{"%Y-%m-%d %H","yyyy年MM月dd日 HH点","H"},
				new String[]{"%m","MM月"},
				new String[]{"%d","dd号"},
				new String[]{"%H","HH点"} 
		};
		
		//获取要分组的字段，放入Map中
		if(dateType>0){
			groups.put(groupKey.toString(),"DATE_FORMAT({key},'"+dateFormats[dateType][0]+"')");
		}else{
			groups.put(groupKey.toString(),"{key}");
		}
		if(dateType<6 && dateType>0){ 
			params.put("asc", groupKey.toString()); 
			if(params.get(groupKey.name()+"Start")==null){
				params.put(groupKey.name()+"Start", Utils.date(new Date(), -24, dateFormats[dateType][2]));
			}
		}
		
		
		//获取要统计的字段，放入Map中
		if(sumKey.toString().equals("count")){
			sums.put(sumKey.toString(),"count(*)");
		}else{
			sums.put(sumKey.toString(),"sum({key})");
		}
		
		List<Map> list = getReplenishmentDao().getReplenishmentStats(params,groups,sums);
		
		List<Map> result = new ArrayList();
		for(Map m:list){
			Map map = new HashMap();
			Object value = m.get(sumKey.toString());
			Object name = null;
			Object groupValue = m.get(groupKey.toString());
			if(dateType>0){
				name = Utils.date(Utils.parseDate(groupValue), dateFormats[dateType][1]);
			}else{
				try{
					java.lang.reflect.Method method = Replenishment.class.getMethod("get"+Utils.ForMat(groupKey.toString())+"$");
					method.setAccessible(true);
					name = method.invoke(Replenishment.fromMap(m));
				}catch(Exception ex){
					ex.printStackTrace();
				}
			}
			map.put("name", name);
			map.put("value", value);
			result.add(map);
		}
		return result;
	}
	
	/**
	 * 根据条件更新数据
	 * @param set
	 * @param where
	 */
	public static int updateReplenishment(Map set,Map where){
		if(set.isEmpty())throw new RuntimeException("set为空");
		if(where.isEmpty())throw new RuntimeException("where为空");
		where.put("confirm", "1");
		return getReplenishmentDao().updateReplenishmentByConfirm(set, where);
	}
	
	
	/**
	 * 根据条件更新数据
	 * @param set
	 * @param where
	 */
	public static void deleteReplenishment(Map where){
		if(where.isEmpty())throw new RuntimeException("where为空");
		where.put("confirm", "1");
		getReplenishmentDao().deleteReplenishmentByConfirm(where);
	}
	
	/**
	 * 根据条件更新数据
	 * @param set
	 * @param where
	 */
	public static void delete(Long id){
		if(id==null)throw new RuntimeException("id为空");
		getReplenishmentDao().removeReplenishmentById(id);
	}
	
	
	/**
	 * 保存补货明细对象
	 * @param params
	 * @return
	 */
	public Replenishment save(){
		if(this.getId()!=null)
			getReplenishmentDao().updateReplenishment(this);
		else
			return getReplenishmentDao().saveReplenishment(this);
		return this;
	}
	
	
	/**
	 * 更新补货明细对象的非空字段,注意跟Service里面的update不一样哦
	 * @param params
	 * @return
	 */
	public int update(){
		return getReplenishmentDao().updateReplenishment$NotNull(this);
	}
	
	
	/**
	 * 删除
	 * @param params
	 * @return
	 */
	public void delete(){
		if(Utils.equals(Utils.config("logic_delete"),"true"))
			getReplenishmentDao().removeReplenishmentById(this.getId());
		else
			getReplenishmentDao().deleteReplenishmentById(this.getId());
	}
	
	/**
	 * 执行事务
	 * @param function
	 */
	public static <T> T execute(Function function){
		return getReplenishmentDao().executeTransaction(function);
	}
	/*******************************编号**********************************/	
	/**
	* 编号 [非空]      
	**/
	public Long getId(){
		if(this.id!=null){
			return this.id;
		}
		return this.id;
	}
	/**
	* 获取编号格式化(toString)
	**/
	public String getId$(){
		String strValue="";
		 strValue=Utils.string(this.getId());
	 	 return strValue;
	}
	/**
	* 根据编号反格式化
	**/
	public void setId$(String strValue){
		if(Utils.empty(strValue)){
			this.id=null;
			return;
		}
	 	this.id=Utils.parseLong(strValue);
	}
	
	/**
	* 编号 [非空]      
	**/
	public void setId(Long id){
		this.id = id;
		this.setSeted(F.id);
	}
	
	
	
	
	/*******************************补货信息**********************************/	
	/**
	* 补货信息 [非空] [Replenish]     
	**/
	public Long getReplenish(){
		if(this.replenish!=null){
			return this.replenish;
		}
		return this.replenish;
	}
	/**
	* 获取补货信息格式化(toString)
	**/
	public String getReplenish$(){
		String strValue="";
		if(this.getReplenish()!=null){
				strValue+=Utils.string(Replenish.getKeyValue(this.getReplenish()));
		}			
	 	 return strValue;
	}
	/**
	* 根据补货信息反格式化
	**/
	public void setReplenish$(String strValue){
		if(Utils.empty(strValue)){
			this.replenish=null;
			return;
		}
		Replenish item = Replenish.find(strValue);
		if(item!=null){
			this.replenish = Utils.parseLong(item.getId());
		}
	}
	
	/**
	* 补货信息 [非空] [Replenish]     
	**/
	public void setReplenish(Long replenish){
		this.replenish = replenish;
		this.setSeted(F.replenish);
	}
	
	
	
	
	/**
	* 获取关联对象[配送商补货]
	**/	 			
 	public Replenish get$replenish(){
 		if(this.$replenish!=null)
 			return this.$replenish;
 		com.distribute.framework.model.Replenish replenish = null;
		if(this.getReplenish()!=null){
 			replenish = Replenish.get(this.getReplenish());
 		}
 		return replenish;
	}
	/*******************************备注**********************************/	
	/**
	* 备注 [非空]      
	**/
	public String getRemarks(){
		if(this.remarks!=null){
			return this.remarks;
		}
		return this.remarks;
	}
	/**
	* 获取备注格式化(toString)
	**/
	public String getRemarks$(){
		String strValue="";
		 strValue=Utils.string(this.getRemarks());
	 	 return strValue;
	}
	/**
	* 根据备注反格式化
	**/
	public void setRemarks$(String strValue){
		if(Utils.empty(strValue)){
			this.remarks=null;
			return;
		}
		this.remarks=strValue;
	}
	
	/**
	* 备注 [非空]      
	**/
	public void setRemarks(String remarks){
		this.remarks = remarks;
		this.setSeted(F.remarks);
	}
	
	
	
	
	/*******************************规格属性**********************************/	
	/**
	* 规格属性       
	**/
	public String getAttribute(){
		if(this.attribute!=null){
			return this.attribute;
		}
		return this.attribute;
	}
	/**
	* 获取规格属性格式化(toString)
	**/
	public String getAttribute$(){
		String strValue="";
		 strValue=Utils.string(this.getAttribute());
	 	 return strValue;
	}
	/**
	* 根据规格属性反格式化
	**/
	public void setAttribute$(String strValue){
		if(Utils.empty(strValue)){
			this.attribute=null;
			return;
		}
	 	this.attribute=strValue;
	}
	
	/**
	* 规格属性       
	**/
	public void setAttribute(String attribute){
		this.attribute = attribute;
		this.setSeted(F.attribute);
	}
	
	
	
	
	/*******************************单位**********************************/	
	/**
	* 单位     商品单位  
	**/
	public String getCompany(){
		if(this.company!=null){
			return this.company;
		}
		return this.company;
	}
	/**
	* 获取单位格式化(toString)
	**/
	public String getCompany$(){
		String strValue="";
		 strValue=Utils.string(this.getCompany());
	 	 return strValue;
	}
	/**
	* 根据单位反格式化
	**/
	public void setCompany$(String strValue){
		if(Utils.empty(strValue)){
			this.company=null;
			return;
		}
	 	this.company=strValue;
	}
	
	/**
	* 单位     商品单位  
	**/
	public void setCompany(String company){
		this.company = company;
		this.setSeted(F.company);
	}
	
	
	
	
	/*******************************已补货**********************************/	
	/**
	* 已补货       
	**/
	public Integer getCount(){
		if(this.count!=null){
			return this.count;
		}
		return this.count;
	}
	/**
	* 获取已补货格式化(toString)
	**/
	public String getCount$(){
		String strValue="";
		 strValue=Utils.string(this.getCount());
	 	 return strValue;
	}
	/**
	* 根据已补货反格式化
	**/
	public void setCount$(String strValue){
		if(Utils.empty(strValue)){
			this.count=null;
			return;
		}
	 	this.count=Utils.parseInteger(strValue);
	}
	
	/**
	* 已补货       
	**/
	public void setCount(Integer count){
		this.count = count;
		this.setSeted(F.count);
	}
	
	
	
	
	/*******************************已配出**********************************/	
	/**
	* 已配出       
	**/
	public Integer getMatchOut(){
		if(this.matchOut!=null){
			return this.matchOut;
		}
		return this.matchOut;
	}
	/**
	* 获取已配出格式化(toString)
	**/
	public String getMatchOut$(){
		String strValue="";
		 strValue=Utils.string(this.getMatchOut());
	 	 return strValue;
	}
	/**
	* 根据已配出反格式化
	**/
	public void setMatchOut$(String strValue){
		if(Utils.empty(strValue)){
			this.matchOut=null;
			return;
		}
	 	this.matchOut=Utils.parseInteger(strValue);
	}
	
	/**
	* 已配出       
	**/
	public void setMatchOut(Integer matchOut){
		this.matchOut = matchOut;
		this.setSeted(F.matchOut);
	}
	
	
	
	
	/*******************************还欠**********************************/	
	/**
	* 还欠       
	**/
	public Integer getOwe(){
		if(this.owe!=null){
			return this.owe;
		}
		return this.owe;
	}
	/**
	* 获取还欠格式化(toString)
	**/
	public String getOwe$(){
		String strValue="";
		 strValue=Utils.string(this.getOwe());
	 	 return strValue;
	}
	/**
	* 根据还欠反格式化
	**/
	public void setOwe$(String strValue){
		if(Utils.empty(strValue)){
			this.owe=null;
			return;
		}
	 	this.owe=Utils.parseInteger(strValue);
	}
	
	/**
	* 还欠       
	**/
	public void setOwe(Integer owe){
		this.owe = owe;
		this.setSeted(F.owe);
	}
	
	
	
	
	/*******************************补货商品**********************************/	
	/**
	* 补货商品 [非空] [Commodity]     
	**/
	public Long getCommodity(){
		if(this.commodity!=null){
			return this.commodity;
		}
		return this.commodity;
	}
	/**
	* 获取补货商品格式化(toString)
	**/
	public String getCommodity$(){
		String strValue="";
		if(this.getCommodity()!=null){
				strValue+=Utils.string(Commodity.getKeyValue(this.getCommodity()));
		}			
	 	 return strValue;
	}
	/**
	* 根据补货商品反格式化
	**/
	public void setCommodity$(String strValue){
		if(Utils.empty(strValue)){
			this.commodity=null;
			return;
		}
		Commodity item = Commodity.find(strValue);
		if(item!=null){
			this.commodity = Utils.parseLong(item.getId());
		}
	}
	
	/**
	* 补货商品 [非空] [Commodity]     
	**/
	public void setCommodity(Long commodity){
		this.commodity = commodity;
		this.setSeted(F.commodity);
	}
	
	
	
	
	/**
	* 获取关联对象[商品信息]
	**/	 			
 	public Commodity get$commodity(){
 		if(this.$commodity!=null)
 			return this.$commodity;
 		com.distribute.framework.model.Commodity commodity = null;
		if(this.getCommodity()!=null){
 			commodity = Commodity.get(this.getCommodity());
 		}
 		return commodity;
	}
	/*******************************修改时间**********************************/	
	/**
	* 修改时间 [非空]      
	**/
	public Date getUpdateTime(){
		if(this.updateTime!=null){
			return this.updateTime;
		}
		return this.updateTime;
	}
	/**
	* 获取修改时间格式化(toString)
	**/
	public String getUpdateTime$(){
		String strValue="";
		 strValue=Utils.string(Utils.date(this.getUpdateTime(),"yyyy-MM-dd HH:mm:ss"));
	 	 return strValue;
	}
	/**
	* 根据修改时间反格式化
	**/
	public void setUpdateTime$(String strValue){
		if(Utils.empty(strValue)){
			this.updateTime=null;
			return;
		}
	 	this.updateTime=Utils.date(strValue,"yyyy-MM-dd HH:mm:ss");
	}
	
	/**
	* 修改时间 [非空]      
	**/
	public void setUpdateTime(Date updateTime){
		this.updateTime = updateTime;
		this.setSeted(F.updateTime);
	}
	
	
	
	
	/*******************************添加时间**********************************/	
	/**
	* 添加时间 [非空]      
	**/
	public Date getAddTime(){
		if(this.addTime!=null){
			return this.addTime;
		}
		return this.addTime;
	}
	/**
	* 获取添加时间格式化(toString)
	**/
	public String getAddTime$(){
		String strValue="";
		 strValue=Utils.string(Utils.date(this.getAddTime(),"yyyy-MM-dd HH:mm:ss"));
	 	 return strValue;
	}
	/**
	* 根据添加时间反格式化
	**/
	public void setAddTime$(String strValue){
		if(Utils.empty(strValue)){
			this.addTime=null;
			return;
		}
	 	this.addTime=Utils.date(strValue,"yyyy-MM-dd HH:mm:ss");
	}
	
	/**
	* 添加时间 [非空]      
	**/
	public void setAddTime(Date addTime){
		this.addTime = addTime;
		this.setSeted(F.addTime);
	}
	
	
	
	
	/*******************************状态**********************************/	
	/**
	* 状态 [非空]   1:正常 0:无效    
	**/
	public Short getStatus(){
		if(this.status!=null){
			return this.status;
		}
		return this.status;
	}
	/**
	* 获取状态格式化(toString)
	**/
	public String getStatus$(){
		String strValue="";
		 if(Utils.equals(Utils.string(this.getStatus()),"1"))
			strValue=Utils.string("正常");		 
		 if(Utils.equals(Utils.string(this.getStatus()),"0"))
			strValue=Utils.string("无效");		 
	 	 return strValue;
	}
	/**
	* 根据状态反格式化
	**/
	public void setStatus$(String strValue){
		if(Utils.empty(strValue)){
			this.status=null;
			return;
		}
		 if(Utils.equals(strValue,"正常"))
		 	this.status=Utils.parseShort("1");
		 if(Utils.equals(strValue,"无效"))
		 	this.status=Utils.parseShort("0");
	}
	
	/**
	* 状态 [非空]   1:正常 0:无效    
	**/
	public void setStatus(Short status){
		this.status = status;
		this.setSeted(F.status);
	}
	
	
	
	
	/************LAZY3Q_DEFINE_CODE************/
	/************LAZY3Q_DEFINE_CODE************/
	
	
	/**
	 * 触发器
	 */
	public static void on(Trigger.Index index,final Notify.Listener listener,Trigger.Type... types){
		Notify.on(Replenishment.class, index, listener, types);
	}
	public static void on(final Notify.Listener listener,String type){
		Notify.on(Replenishment.class, listener, type);
	}
	/**
	 * 当修改字段时
	 * @param filedName
	 * @param listener
	 */
	public static void on(String filedName,final Notify.Listener listener){
		Notify.on(Replenishment.class, listener, filedName);
	}
	/**
	 * 当修改字段为某值时
	 * @param filedName
	 * @param value
	 * @param listener
	 */
	public static void on(String filedName,Object value,final Notify.Listener listener){
		if(value==null)return;
		Notify.on(Replenishment.class, listener, filedName+"."+Utils.md5(""+value));
	}
	public void notify(String type){
		Trigger.on(Replenishment.class,type, this);
	}
	
	
	/**
	 * 用来获取当有字段关联对象时的获取方式,调用如${Replenishment.obj.filedName}
	 * 因为有些变态的模板语言不能识别$，所以不能以${Replenishment.$filedName}获取关联对象
	 */
	public Map getObj(){
		return new HashMap(){
			@Override
			public Object get(Object key) {
				try {
					return Replenishment.class.getMethod("get$"+Utils.forMat(key.toString())).invoke(Replenishment.this);
				} catch (Exception e) {
					e.printStackTrace();
				}
				return null;
			}
		};
	}
	/**
	 * 用来获取某字段格式化的获取方式,调用如${Replenishment.fmt.filedName}
	 * 因为有些变态的模板语言不能识别$，所以不能以${Replenishment.filedName$}获取某字段格式化
	 */
	public Map getFmt(){
		return new HashMap(){
			@Override
			public Object get(Object key) {
				try {
					return Replenishment.class.getMethod("get"+Utils.ForMat(key.toString()+"$")).invoke(Replenishment.this);
				} catch (Exception e) {
					e.printStackTrace();
				}
				return null;
			}
		};
	}
	/**
	 * 获取查询参数链式串
	 * @return
	 */
	public static @Deprecated M where(){ return new M(0); }
	public static @Deprecated M m(){ return new M(0); }
	public static M where = new M(0,true);
	public static @database(DatabaseNames.distribute_sys) class M extends IbatisMap{
		int type = 0; 
		M linked = null;
		Boolean proxy = false;
		public M set = null;
		public M(int type){
			this.type = type;
			if(this.type==0){
				set = new M(1,true);
				set.linked = this;
			}
		};
		public M(int type,Boolean proxy){
			this.type = type;
			this.proxy=proxy;
		};
		public M proxy(){
			M m = new M(this.type);//当前的对像
			if(this.type==0){
				m.set = new M(1,true);//set对象
				m.set.linked = m;
			}else{
				m.linked=this.linked;
				this.linked.linked=m;
			}
			return m;
		}
		public @Deprecated M set(){			
			M m = this;
			m.linked=new M(1);
			m.linked.linked=m;
			return m.linked;
		};
		public M on(IbatisMap value,C column,String joinColumn){if(proxy)return proxy().on(value,column,joinColumn);this.put(value.getClass().getDeclaringClass().getSimpleName(), value);value.put("on", column.toString());value.put("to", joinColumn);return this;};
		/** 编号 [非空]       **/
		public M id(Object id){if(proxy)return proxy().id(id);  this.put("id", id);return this;};
	 	/** and id is null */
 		public M idNull(){if(proxy)return proxy().idNull();if(this.get("idNot")==null)this.put("idNot", "");this.put("id", null);return this;};
 		/** not .... */
 		public M idNot(){if(proxy)return proxy().idNot();this.put("idNot", "not");return this;};
 		public M idNotNull(){if(proxy)return proxy().idNotNull();this.put("idNot", "not");this.put("id", null);return this;};
 		public M idNot(Object id){if(proxy)return proxy().idNot(id);this.put("idNot", "not");this.put("id", id);return this;};
		/** and id <= ? */
		public M idMin(Object min){if(proxy)return proxy().idMin(min);this.put("idMin", min);return this;};
		/** and id >= ? */
		public M idMax(Object max){if(proxy)return proxy().idMax(max);this.put("idMax", max);return this;};
		public M idIn(String ids){
			if(proxy)return proxy().idIn(ids);  this.put("idIn", ids);return this;
		};	
		public M replenish$on(Replenish.M value){if(proxy)return proxy().replenish$on(value);this.put("Replenish", value);value.put("on", "replenish");return this;};
		/** 补货信息 [非空] [Replenish]      **/
		public M replenish(Object replenish){if(proxy)return proxy().replenish(replenish);  this.put("replenish", replenish);return this;};
	 	/** and replenish is null */
 		public M replenishNull(){if(proxy)return proxy().replenishNull();if(this.get("replenishNot")==null)this.put("replenishNot", "");this.put("replenish", null);return this;};
 		/** not .... */
 		public M replenishNot(){if(proxy)return proxy().replenishNot();this.put("replenishNot", "not");return this;};
 		public M replenishNotNull(){if(proxy)return proxy().replenishNotNull();this.put("replenishNot", "not");this.put("replenish", null);return this;};
 		public M replenishNot(Object replenish){if(proxy)return proxy().replenishNot(replenish);this.put("replenishNot", "not");this.put("replenish", replenish);return this;};
		public M replenishIn(String ids){
			if(proxy)return proxy().replenishIn(ids);  this.put("replenishIn", ids);return this;
		};	
		/** 备注 [非空]       **/
		public M remarks(Object remarks){if(proxy)return proxy().remarks(remarks);  this.put("remarks", remarks);return this;};
	 	/** and remarks is null */
 		public M remarksNull(){if(proxy)return proxy().remarksNull();if(this.get("remarksNot")==null)this.put("remarksNot", "");this.put("remarks", null);return this;};
 		/** not .... */
 		public M remarksNot(){if(proxy)return proxy().remarksNot();this.put("remarksNot", "not");return this;};
 		public M remarksNotNull(){if(proxy)return proxy().remarksNotNull();this.put("remarksNot", "not");this.put("remarks", null);return this;};
 		public M remarksNot(Object remarks){if(proxy)return proxy().remarksNot(remarks);this.put("remarksNot", "not");this.put("remarks", remarks);return this;};
		/** 规格属性        **/
		public M attribute(Object attribute){if(proxy)return proxy().attribute(attribute);  this.put("attribute", attribute);return this;};
	 	/** and attribute is null */
 		public M attributeNull(){if(proxy)return proxy().attributeNull();if(this.get("attributeNot")==null)this.put("attributeNot", "");this.put("attribute", null);return this;};
 		/** not .... */
 		public M attributeNot(){if(proxy)return proxy().attributeNot();this.put("attributeNot", "not");return this;};
 		public M attributeNotNull(){if(proxy)return proxy().attributeNotNull();this.put("attributeNot", "not");this.put("attribute", null);return this;};
 		public M attributeNot(Object attribute){if(proxy)return proxy().attributeNot(attribute);this.put("attributeNot", "not");this.put("attribute", attribute);return this;};
		/** 单位     商品单位   **/
		public M company(Object company){if(proxy)return proxy().company(company);  this.put("company", company);return this;};
	 	/** and company is null */
 		public M companyNull(){if(proxy)return proxy().companyNull();if(this.get("companyNot")==null)this.put("companyNot", "");this.put("company", null);return this;};
 		/** not .... */
 		public M companyNot(){if(proxy)return proxy().companyNot();this.put("companyNot", "not");return this;};
 		public M companyNotNull(){if(proxy)return proxy().companyNotNull();this.put("companyNot", "not");this.put("company", null);return this;};
 		public M companyNot(Object company){if(proxy)return proxy().companyNot(company);this.put("companyNot", "not");this.put("company", company);return this;};
		/** 已补货        **/
		public M count(Object count){if(proxy)return proxy().count(count);  this.put("count", count);return this;};
	 	/** and count is null */
 		public M countNull(){if(proxy)return proxy().countNull();if(this.get("countNot")==null)this.put("countNot", "");this.put("count", null);return this;};
 		/** not .... */
 		public M countNot(){if(proxy)return proxy().countNot();this.put("countNot", "not");return this;};
 		public M countNotNull(){if(proxy)return proxy().countNotNull();this.put("countNot", "not");this.put("count", null);return this;};
 		public M countNot(Object count){if(proxy)return proxy().countNot(count);this.put("countNot", "not");this.put("count", count);return this;};
		/** and count <= ? */
		public M countMin(Object min){if(proxy)return proxy().countMin(min);this.put("countMin", min);return this;};
		/** and count >= ? */
		public M countMax(Object max){if(proxy)return proxy().countMax(max);this.put("countMax", max);return this;};
		public M countIn(String ids){
			if(proxy)return proxy().countIn(ids);  this.put("countIn", ids);return this;
		};	
		/** 已配出        **/
		public M matchOut(Object matchOut){if(proxy)return proxy().matchOut(matchOut);  this.put("matchOut", matchOut);return this;};
	 	/** and match_out is null */
 		public M matchOutNull(){if(proxy)return proxy().matchOutNull();if(this.get("matchOutNot")==null)this.put("matchOutNot", "");this.put("matchOut", null);return this;};
 		/** not .... */
 		public M matchOutNot(){if(proxy)return proxy().matchOutNot();this.put("matchOutNot", "not");return this;};
 		public M matchOutNotNull(){if(proxy)return proxy().matchOutNotNull();this.put("matchOutNot", "not");this.put("matchOut", null);return this;};
 		public M matchOutNot(Object matchOut){if(proxy)return proxy().matchOutNot(matchOut);this.put("matchOutNot", "not");this.put("matchOut", matchOut);return this;};
		/** and match_out <= ? */
		public M matchOutMin(Object min){if(proxy)return proxy().matchOutMin(min);this.put("matchOutMin", min);return this;};
		/** and match_out >= ? */
		public M matchOutMax(Object max){if(proxy)return proxy().matchOutMax(max);this.put("matchOutMax", max);return this;};
		public M matchOutIn(String ids){
			if(proxy)return proxy().matchOutIn(ids);  this.put("matchOutIn", ids);return this;
		};	
		/** 还欠        **/
		public M owe(Object owe){if(proxy)return proxy().owe(owe);  this.put("owe", owe);return this;};
	 	/** and owe is null */
 		public M oweNull(){if(proxy)return proxy().oweNull();if(this.get("oweNot")==null)this.put("oweNot", "");this.put("owe", null);return this;};
 		/** not .... */
 		public M oweNot(){if(proxy)return proxy().oweNot();this.put("oweNot", "not");return this;};
 		public M oweNotNull(){if(proxy)return proxy().oweNotNull();this.put("oweNot", "not");this.put("owe", null);return this;};
 		public M oweNot(Object owe){if(proxy)return proxy().oweNot(owe);this.put("oweNot", "not");this.put("owe", owe);return this;};
		/** and owe <= ? */
		public M oweMin(Object min){if(proxy)return proxy().oweMin(min);this.put("oweMin", min);return this;};
		/** and owe >= ? */
		public M oweMax(Object max){if(proxy)return proxy().oweMax(max);this.put("oweMax", max);return this;};
		public M oweIn(String ids){
			if(proxy)return proxy().oweIn(ids);  this.put("oweIn", ids);return this;
		};	
		public M commodity$on(Commodity.M value){if(proxy)return proxy().commodity$on(value);this.put("Commodity", value);value.put("on", "commodity");return this;};
		/** 补货商品 [非空] [Commodity]      **/
		public M commodity(Object commodity){if(proxy)return proxy().commodity(commodity);  this.put("commodity", commodity);return this;};
	 	/** and commodity is null */
 		public M commodityNull(){if(proxy)return proxy().commodityNull();if(this.get("commodityNot")==null)this.put("commodityNot", "");this.put("commodity", null);return this;};
 		/** not .... */
 		public M commodityNot(){if(proxy)return proxy().commodityNot();this.put("commodityNot", "not");return this;};
 		public M commodityNotNull(){if(proxy)return proxy().commodityNotNull();this.put("commodityNot", "not");this.put("commodity", null);return this;};
 		public M commodityNot(Object commodity){if(proxy)return proxy().commodityNot(commodity);this.put("commodityNot", "not");this.put("commodity", commodity);return this;};
		public M commodityIn(String ids){
			if(proxy)return proxy().commodityIn(ids);  this.put("commodityIn", ids);return this;
		};	
		/** 修改时间 [非空]       **/
		public M updateTime(Object updateTime){if(proxy)return proxy().updateTime(updateTime);  this.put("updateTime", updateTime);return this;};
	 	/** and update_time is null */
 		public M updateTimeNull(){if(proxy)return proxy().updateTimeNull();if(this.get("updateTimeNot")==null)this.put("updateTimeNot", "");this.put("updateTime", null);return this;};
 		/** not .... */
 		public M updateTimeNot(){if(proxy)return proxy().updateTimeNot();this.put("updateTimeNot", "not");return this;};
 		public M updateTimeNotNull(){if(proxy)return proxy().updateTimeNotNull();this.put("updateTimeNot", "not");this.put("updateTime", null);return this;};
 		public M updateTimeNot(Object updateTime){if(proxy)return proxy().updateTimeNot(updateTime);this.put("updateTimeNot", "not");this.put("updateTime", updateTime);return this;};
 		/** and update_time >= ? */
 		public M updateTimeStart(Object start){if(proxy)return proxy().updateTimeStart(start);this.put("updateTimeStart", start);return this;};			
 		/** and update_time <= ? */
 		public M updateTimeEnd(Object end){if(proxy)return proxy().updateTimeEnd(end);this.put("updateTimeEnd", end);return this;};
		/** 添加时间 [非空]       **/
		public M addTime(Object addTime){if(proxy)return proxy().addTime(addTime);  this.put("addTime", addTime);return this;};
	 	/** and add_time is null */
 		public M addTimeNull(){if(proxy)return proxy().addTimeNull();if(this.get("addTimeNot")==null)this.put("addTimeNot", "");this.put("addTime", null);return this;};
 		/** not .... */
 		public M addTimeNot(){if(proxy)return proxy().addTimeNot();this.put("addTimeNot", "not");return this;};
 		public M addTimeNotNull(){if(proxy)return proxy().addTimeNotNull();this.put("addTimeNot", "not");this.put("addTime", null);return this;};
 		public M addTimeNot(Object addTime){if(proxy)return proxy().addTimeNot(addTime);this.put("addTimeNot", "not");this.put("addTime", addTime);return this;};
 		/** and add_time >= ? */
 		public M addTimeStart(Object start){if(proxy)return proxy().addTimeStart(start);this.put("addTimeStart", start);return this;};			
 		/** and add_time <= ? */
 		public M addTimeEnd(Object end){if(proxy)return proxy().addTimeEnd(end);this.put("addTimeEnd", end);return this;};
		/** 状态 [非空]   1:正常 0:无效     **/
		public M status(Object status){if(proxy)return proxy().status(status);  this.put("status", status);return this;};
	 	/** and status is null */
 		public M statusNull(){if(proxy)return proxy().statusNull();if(this.get("statusNot")==null)this.put("statusNot", "");this.put("status", null);return this;};
 		/** not .... */
 		public M statusNot(){if(proxy)return proxy().statusNot();this.put("statusNot", "not");return this;};
 		public M statusNotNull(){if(proxy)return proxy().statusNotNull();this.put("statusNot", "not");this.put("status", null);return this;};
 		public M statusNot(Object status){if(proxy)return proxy().statusNot(status);this.put("statusNot", "not");this.put("status", status);return this;};
		public M statusIn(String ids){
			if(proxy)return proxy().statusIn(ids);  this.put("statusIn", ids);return this;
		};	
	 	public M add(String key, Object value) {if(proxy)return proxy().add(key,value);this.put(key, value);return this;}
	 	public M add(F key, Object value) {if(proxy)return proxy().add(key,value);this.put(key.toString(), value);return this;}
	 	public M desc(C key) {if(proxy)return proxy().desc(key);this.put("desc", key.column);return this;}
	 	public M asc(C key) {if(proxy)return proxy().asc(key);this.put("asc", key.column);return this;}
	 	public M desc(String sql) {if(proxy)return proxy().desc(sql);this.put("desc", sql);return this;}
	 	public M asc(String sql) {if(proxy)return proxy().asc(sql);this.put("asc", sql);return this;}
	 	public M definex(String sql) {if(proxy)return proxy().definex(sql);this.put("definex", sql);return this;}
	 	/** 获取所有补货明细 **/
		public @api List<Replenishment> list(Integer size){			
			return getReplenishmentList(this,size);
		}
		/** 获取补货明细分页 **/
		public @api Page<Replenishment> page(Integer page,Integer size){			
			return getReplenishmentPage(page, size , this);
		}
		/** 根据查询条件取补货明细 **/
		public @api Replenishment get(){			
			return getReplenishment(this);
		}
		/** 获取补货明细数 **/
		public @api Long count(){			
			return getReplenishmentCount(this);
		}
		/** 获取补货明细表达式 **/
		public @api <T> T eval(String strEval){			
			return getReplenishmentEval(strEval,this);
		}
		/** 获取补货明细统计 **/
		public @api List<Map> stats(C sumKey,C groupKey,int dateType){			
			return getReplenishmentStats(this,sumKey,groupKey,dateType);
		}
		/** 获取补货明细统计 **/
		public @api List<Map> stats(C sumKey,C groupKey){			
			return getReplenishmentStats(this,sumKey,groupKey,-1);
		}
		/** 根据条件更新 **/
		public @api int update(){			
			M where = null;
			M set = null;
			if(this.type==0){
				if(this.linked==null)throw new RuntimeException("未发set");
				where = this;
				set = this.linked;
			}else{
				if(this.linked==null)throw new RuntimeException("未发where条件");
				set = this;
				where = this.linked;
			}
			return updateReplenishment(set,where);
		}
		/** 根据条件删除 **/
		public @api void delete(){			
			deleteReplenishment(this);
		}
	}
	
	public static class Param extends M{
		public Param(int type) {
			super(type);
		}
		public Param(int type, Boolean proxy) {
			super(type, proxy);
		}
	}
	
	/** 对象的字段描述 **/
	public static class F{
		/** 编号 [非空]       **/
		public final static @type(Long.class)  String id="id";
		/** 补货信息 [非空] [Replenish]      **/
		public final static @type(Long.class)  String replenish="replenish";
		/** 备注 [非空]       **/
		public final static @type(String.class) @like String remarks="remarks";
		/** 规格属性        **/
		public final static @type(String.class)  String attribute="attribute";
		/** 单位     商品单位   **/
		public final static @type(String.class)  String company="company";
		/** 已补货        **/
		public final static @type(Integer.class)  String count="count";
		/** and count >= ? */
		public final static @type(Integer.class) String countMin="countMin";
		/** and count <= ? */
		public final static @type(Integer.class) String countMax="countMax";
		/** 已配出        **/
		public final static @type(Integer.class)  String matchOut="matchOut";
		/** and match_out >= ? */
		public final static @type(Integer.class) String matchOutMin="matchOutMin";
		/** and match_out <= ? */
		public final static @type(Integer.class) String matchOutMax="matchOutMax";
		/** 还欠        **/
		public final static @type(Integer.class)  String owe="owe";
		/** and owe >= ? */
		public final static @type(Integer.class) String oweMin="oweMin";
		/** and owe <= ? */
		public final static @type(Integer.class) String oweMax="oweMax";
		/** 补货商品 [非空] [Commodity]      **/
		public final static @type(Long.class)  String commodity="commodity";
		/** 修改时间 [非空]       **/
		public final static @type(Date.class)  String updateTime="updateTime";
	 	/** and update_time >= ? */
 		public final static @type(Date.class) String updateTimeStart="updateTimeStart";
 		/** and update_time <= ? */
 		public final static @type(Date.class) String updateTimeEnd="updateTimeEnd";
		/** 添加时间 [非空]       **/
		public final static @type(Date.class)  String addTime="addTime";
	 	/** and add_time >= ? */
 		public final static @type(Date.class) String addTimeStart="addTimeStart";
 		/** and add_time <= ? */
 		public final static @type(Date.class) String addTimeEnd="addTimeEnd";
		/** 状态 [非空]   1:正常 0:无效     **/
		public final static @type(Short.class)  String status="status";
	 	public static String get(String name){
			try {
				Field field = F.class.getField(name);
				if(field!=null)
					return field.get(null).toString();
			} catch (Exception e) {
				//e.printStackTrace();
			}
			return null;
		}
	}
	/** 对象的数据库字段描述 **/
	public static enum C{
		id("id"),
		replenish("replenish"),
		remarks("remarks"),
		attribute("attribute"),
		company("company"),
		count("count"),
		matchOut("match_out"),
		owe("owe"),
		commodity("commodity"),
		updateTime("update_time"),
		addTime("add_time"),
		status("status"),
		;
		String column;
		C(String column){
			this.column = column;
		}
		public String toString(){
			return this.column;
		}
		public static String get(String name){
			try {
				Field field = C.class.getField(name);
				if(field!=null)
					return field.get(null).toString();
			} catch (Exception e) {
				//e.printStackTrace();
			}
			return null;
		}
	}
	
	
	
	/**
	* 获取补货明细数据
	**/
	public static Object getData(Object param){
		if(param==null)
			return null;
		Object value = null;
		if(param.getClass()==Long.class)
			value = Replenishment.get((Long)param);
		else if(param instanceof java.util.Map){
			java.util.Map params = (Map) param;
			if(params.get("size")==null)
				value = Replenishment.getReplenishment(params);
			else
				value = Replenishment.getReplenishmentList(params, (Integer) params.get("size"));
		}else if(param.getClass()==Long.class )
			value =  Replenishment.where().id(param).get();
		else if(!Utils.empty(param.toString()))
			value = Replenishment.get(Long.valueOf(param.toString()));
		return value;
	}
	
	/**对象转json**/
	public Map toJSON(){
		return toJSON(false);
	}
	public Map toJSON(boolean simple){
		Map map = new HashMap();
		map.put("id",this.getId());
		Utils.fms(map,simple?"":"id",this.getId(),this.getId$());
		Utils.fms(map,simple?"":"replenish",this.getReplenish(),this.getReplenish$());
		Utils.fms(map,simple?"":"remarks",this.getRemarks(),this.getRemarks$());
		Utils.fms(map,simple?"":"attribute",this.getAttribute(),this.getAttribute$());
		Utils.fms(map,simple?"":"company",this.getCompany(),this.getCompany$());
		Utils.fms(map,simple?"":"count",this.getCount(),this.getCount$());
		Utils.fms(map,simple?"out":"matchOut",this.getMatchOut(),this.getMatchOut$());
		Utils.fms(map,simple?"":"owe",this.getOwe(),this.getOwe$());
		Utils.fms(map,simple?"":"commodity",this.getCommodity(),this.getCommodity$());
		Utils.fms(map,simple?"time":"updateTime",this.getUpdateTime(),this.getUpdateTime$());
		Utils.fms(map,simple?"time":"addTime",this.getAddTime(),this.getAddTime$());
		Utils.fms(map,simple?"":"status",this.getStatus(),this.getStatus$());
		if(this.suffix!=null)map.put("suffix", this.suffix);
		/************LAZY3Q_DEFINE_TOJSON************/
		/************LAZY3Q_DEFINE_TOJSON************/
		return map;
	}
	/**对象转map**/
	public Map toMap(){
		Map map = new HashMap();
		map.put("id",this.getId());
		map.put("replenish",this.getReplenish());
		map.put("remarks",this.getRemarks());
		map.put("attribute",this.getAttribute());
		map.put("company",this.getCompany());
		map.put("count",this.getCount());
		map.put("matchOut",this.getMatchOut());
		map.put("owe",this.getOwe());
		map.put("commodity",this.getCommodity());
		map.put("updateTime",this.getUpdateTime());
		map.put("addTime",this.getAddTime());
		map.put("status",this.getStatus());
		map.put("suffix", this.suffix);
		/************LAZY3Q_DEFINE_TOMAP************/
		/************LAZY3Q_DEFINE_TOMAP************/
		return map;
	}
	/**map转对象**/
	public static Replenishment fromMap(Map map){
		Replenishment replenishment = new Replenishment();
		replenishment.id = Utils.parseLong(map.get("id"));
		replenishment.replenish = Utils.parseLong(map.get("replenish"));
		replenishment.remarks = Utils.parseString(map.get("remarks"));
		replenishment.attribute = Utils.parseString(map.get("attribute"));
		replenishment.company = Utils.parseString(map.get("company"));
		replenishment.count = Utils.parseInteger(map.get("count"));
		replenishment.matchOut = Utils.parseInteger(map.get("matchOut"));
		replenishment.owe = Utils.parseInteger(map.get("owe"));
		replenishment.commodity = Utils.parseLong(map.get("commodity"));
		replenishment.updateTime = Utils.parseDate(map.get("updateTime"));
		replenishment.addTime = Utils.parseDate(map.get("addTime"));
		replenishment.status = Utils.parseShort(map.get("status"));
		return replenishment;
	}
	
	
	/**
	* 设置默认值
	**/
	public void setDefaultValue(String type){
		Replenishment replenishment = this;
		if(type.equals("insert")){//添加时
			if(replenishment.getUpdateTime()==null)
				replenishment.setUpdateTime(new Date());
			if(replenishment.getAddTime()==null)
				replenishment.setAddTime(new Date());
			if(replenishment.getStatus()==null)
				replenishment.setStatus((short)1);
		}else if(type.equals("update")){//编辑时
			replenishment.setUpdateTime(new Date());
		}
	}
	
	
	/**字段设置标记队列**/
	private Map<String,Boolean> seted=new HashMap();
	public Boolean getSeted(String key){
		return seted.get(key);
	}
	public void setSeted(String key){
		seted.put(key,true);
	}
	/**同步未set的字段**/
	public void mergeSet(Replenishment old){
		Field[] fields = this.getClass().getDeclaredFields();
		try {
			for(Field field:fields){
				String key = field.getName();
				if(seted.get(key)==null && field.getAnnotation(column.class)!=null){
					field.setAccessible(true);
					field.set(this, field.get(old));					
				}
			}
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
	
		
	/**自定义变量存储**/
	private Map values=new HashMap();
	public Map getValues(){
		return values;
	}
	public void setValues(String name,Object value){
		values.put(name,value);
	}
	
	/**分表时的表名后缀**/
	private String suffix;
	public String getSuffix() {
		return suffix;
	}
	public void setSuffix(String suffix) {
		this.suffix = suffix;
	}
	/**获取数据库名称**/
	public static String getDataBaseName(){
		return Utils.config("spring.datasource.distribute_sys.name");
	}
	
	public static String getIcon(){
		return "/images/icons/Badge-tick.png";
	}
	public static String getIconfont(){
		return "icon-weibiaoti8";
	}
	public static enum ACT{
		列表,添加,修改,详情
	};
	public static String getUrl(ACT act,Replenishment.M params){
		if(params==null)params=new Replenishment.M(0);
		params.remove("joins");
		params.remove("definexs");
		params.remove("distinct");
		String strUrl = "/admin/delivery/replenishment.edit.html?";
		if(params.get("id")!=null){
			strUrl+="&id="+Utils.encode(""+params.get("id"),Utils.UTF8);
		}
		if(act==ACT.列表){
			strUrl = "/admin/delivery/replenishment.html?1=1";
		}else if(act==ACT.添加){
			strUrl+="&edittype=insert";
		}else if(act==ACT.修改){
			strUrl+="&edittype=update";
		}else if(act==ACT.详情){
			strUrl+="&edittype=detail";
		}		
		if(params!=null){
			for(Object key:params.keySet()){
				strUrl+="&"+key+"="+Utils.encode(""+params.get(key),Utils.UTF8)+"";
			}
		}
		return strUrl;
	}
	public String getDetailUrl(){
		return this.getUrl(ACT.详情, where.id(this.getId()));
	}
	
	/**
	* 转跳到当前地址
	**/
	public static Protocol redirect(Replenishment.ACT act,Replenishment.M params){
		Protocol protocol = Protocol.create(true,null,"ACT_REDIRECT");
		protocol.set("url",Replenishment.getUrl(act, params));
		return protocol;
	}
	/**
	* 打开一个新的tab页面
	**/
	public static Protocol href(Replenishment.ACT act,Replenishment.M params){
		Protocol protocol = Protocol.create(true,null,"ACT_HREF");
		protocol.set("url",Replenishment.getUrl(act, params));
		protocol.set("title",act.name());
		return protocol;
	}
	/**
	* 显示一个消息框，并且关闭当前的对话框
	**/
	public static Protocol message(String message){
		Protocol protocol = Protocol.create(true,null,"ACT_MESSAGE");
		protocol.set("message",message);
		return protocol;
	}
	
	
	static com.distribute.framework.dao.IReplenishmentDao getReplenishmentDao(){
		return Utils.getBean("replenishmentDao");
	};
	
}